package com.xm.settlement.controller;

import com.xm.settlement.commons.base.BaseController;
import com.xm.settlement.commons.utils.PageInfo;
import com.xm.settlement.model.AppService;
import com.xm.settlement.service.IAppServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/3/8.
 */
@Controller
@RequestMapping("/appService")
public class AppServiceController extends BaseController {

    @Autowired
    private IAppServiceService appServiceService;

    /**
     * 服务中心主页
     *
     * @return
     */
    @GetMapping(value = "/manager")
    public String Manager() {
        return "shop/appService/appService";
    }

    /**
     * 服务中心管理
     * @param page
     * @param rows
     * @param sort
     * @param order
     * @return
     */
    @PostMapping("/dataGrid")
    @ResponseBody
    public Object dataGrid(Integer page, Integer rows, String sort, String order) {
        Long Lid = getUserId();
        PageInfo pageInfo = new PageInfo (page, rows, sort, order);
        Map<String, Object> condition = new HashMap<String, Object>();
        pageInfo.setCondition(condition);
        appServiceService.selectDataGrid(pageInfo,Lid);
        return pageInfo;
    }

    /**
     * 添加服务中心页
     *
     * @return
     */
    @RequestMapping("/addPage")
    public String addPage() {
        return "shop/appService/appServiceAdd";
    }

    /**
     * 添加服务中心
     *
     * @param appService
                * @return
     */
        @PostMapping("/add")
        @ResponseBody
        public Object add(AppService appService) {
            appService.setUpdateId(getUserId());
            appServiceService.addService(appService);
            return renderSuccess("添加成功！");
    }

    /**
     * 编辑服务中心页
     *
     * @param model
     * @param id
     * @return
     */
    @GetMapping("/editPage")
    public String editPage(Model model, Long id) {
        AppService appService = appServiceService.selectById(id);
        model.addAttribute("appService", appService);
        return "shop/appService/appServiceEdit";
    }

    /**
     * 编辑服务中心
     *
     * @param appService
     * @return
     */
    @RequestMapping("/edit")
    @ResponseBody
    public Object edit(AppService appService) {
        appService.setUpdateId(getUserId());
        appService.setUpdateTime(new Date());
        appServiceService.updateSelectiveById(appService);
        return renderSuccess("编辑成功！");
    }

    /**
     * 删除订单分类管理
     *
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id) {
        appServiceService.deleteById(id);
        return renderSuccess("删除成功！");
    }
}